package com.rk.kbk.controller.core;

import com.rk.kbk.common.JsonCodeEnum;
import com.rk.kbk.common.JsonResp;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * 错误代理
 */
@ControllerAdvice
public class FrameControllerAdvice {
	private static Logger logger = Logger.getLogger(FrameControllerAdvice.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String processUnauthenticatedException(NativeWebRequest request,Exception e) {
        logger.error(e.getMessage());
        JsonResp jsonResp;
        if (JsonCodeEnum.OVERTIME.getMessage().equals(e.getMessage())) {
            jsonResp = JsonResp.overtime();
        }else{
            jsonResp = JsonResp.toFail(e.getMessage());
            e.printStackTrace();
        }
        return jsonResp.toJson();
    }
}
